package com.liuzu.esys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liuzu.esys.common.LayuiPageVo;
import com.liuzu.esys.mapper.FinTotalMapper;
import com.liuzu.esys.pojo.FinTotal;
import com.liuzu.esys.service.FinTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @author : 松松
 * @date : 2022/7/27
 * @desc :
 */

@Service("ftService")
public class FinTotalServiceImpl implements FinTotalService {

    @Autowired
    private FinTotalMapper finTotalMapper;

    //查询分页
    @Override
    public LayuiPageVo<FinTotal> ftList(@RequestParam Map<String, Object> params) {
        //mybatis 的 分页查询
        Integer page = Integer.parseInt(params.get("page") + "");
        Integer limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page, limit);

        List<FinTotal> finTotalList = finTotalMapper.selectByEample(params);

        //mybatis 的 分页数据结构
        PageInfo<FinTotal> finTotalPageInfo = new PageInfo<>(finTotalList);
        //把 mybatis 的分页数据封装到 layui的分页数据结构中
        LayuiPageVo<FinTotal> finTotalLayuiPageVo = new LayuiPageVo<>();
        finTotalLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        finTotalLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        finTotalLayuiPageVo.setCount((long) finTotalPageInfo.getTotal()); // 总记录数
        finTotalLayuiPageVo.setData(finTotalPageInfo.getList());  // 分页的列表数据
        return finTotalLayuiPageVo;
    }

    //添加
    @Override
    public int addft(FinTotal finTotal) {
        return finTotalMapper.addft(finTotal);
    }

    //删除
    @Override
    public int delft(Integer id) {
        return finTotalMapper.delft(id);
    }

    //修改
    @Override
    public int setft(FinTotal finTotal) {
        return finTotalMapper.setft(finTotal);
    }
}
